package equipmentBusiness;

import impl.TestServerBusinessImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import models.MyConfig;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by yangxianming on 2018/1/16.
 * 创建需要导入的excel，并下载改文件
 */
public class DownFile implements TestServerBusinessImpl {
    @Override
    public String doIt(HttpServletRequest request, MyConfig myConfig) {
        JSONObject returnJson = JSON.parseObject("{\"apistatus\":0,\"result\":\"\",\"errorMsg\":\"\"}");
        String appPath = myConfig.getPropertiesConfig().getProperties().getProperty("appPath");
        String fileName = request.getParameter("fileName");
        boolean isSuccess;

        CreateTestFile createTestFile = new CreateTestFile(appPath);
        isSuccess = createTestFile.test(fileName);

        if (isSuccess){
            returnJson.put("apistatus", 1);
            return returnJson.toString();
        }else {
            returnJson.put("errorMsg", "Excel File upload failure");
            return returnJson.toString();
        }
    }

}
